package com.xianggu.demo.pattern.strategy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileReadingStrategyDemo {
    public static void main(String[] args) throws IOException {
        // 初始优先级为a, b, c, d
        List<FileReaderStrategy> strategies = new ArrayList<>();
        strategies.add(new FileAReaderStrategy());
        strategies.add(new FileBReaderStrategy());
        strategies.add(new FileCReaderStrategy());
        strategies.add(new FileDReaderStrategy());

        FileReaderContext context = new FileReaderContext(strategies);
        String result = context.readFile();
        if (result!= null) {
            System.out.println(result);
        } else {
            System.out.println("No file could be read.");
        }
    }
}